<?php
/**
 *
 * 用户控制器。
 *
 **/

namespace Admin\Controller;

class UserController extends ComController
{

    private $num = 3;

    /**
     * 用户展示列表
     */
    public function index($p = 1)
    {

        $user = M('user');
        $prefix = C('DB_PREFIX');

        $p = intval($p) > 0 ? $p : 1;
        $pagesize = $this->num;#每页数量
        $offset   = $pagesize * ($p - 1);//计算记录偏移量

        // 搜索条件
        $username = isset($_GET['username']) ? htmlentities($_GET['username']) : '';

        if ($username) {
            $where1 = " username like '%{$username}%' ";
            $where  = "  {$prefix}user.username like '%{$username}%' ";
        }

        $count = $user->where($where1)->count();

        $info  = $user
                    ->join("{$prefix}member on {$prefix}user.school_id = {$prefix}member.uid")
                    ->field("{$prefix}user.id,{$prefix}user.pro,{$prefix}member.name,{$prefix}user.phone,{$prefix}user.username,{$prefix}user.id_card,{$prefix}user.schedule")
                    ->where($where)
                    ->limit($offset . ',' . $pagesize)
                    ->select();

        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('userInfo',$info);
        $this->assign('page', $page);
        $this->display();
    }



















    /*************************  以下部分暂时无用  ****************************/

    /**
     * 修改用户的考试进度
     */
    public function schedule()
    {
        $where['id'] = $_GET['uid'];
        $info = M('user')->where($where)->find();
        $this->assign('userInfo',$info);
        $this->display();
    }

    public function update()
    {
        $res = M('user')->save($_POST);
        if($res){
            $this->success('修改成功',U('index'));
        }else{
            $this->error('修改失败',U('index'));
        }
    }
}